package ProTest;
import com.alibaba.excel.EasyExcel;
import dao.BookMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import pojo.Books;
import pojo.PageBean;
import service.BookService;

import java.util.ArrayList;
import java.util.List;
public class test1 {
    @Test
    public void t1(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookService bookServiceImpl = context.getBean("bookServiceImpl", BookService.class);
        List<Books> books = bookServiceImpl.queryAllBook();
        System.out.println("  --}=========>"+books.get(0));
    }
    @Test
    public void t2(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookService bookServiceImpl = context.getBean("bookServiceImpl", BookService.class);
        Books books=new Books();
        books.setBookName("雪中悍刀行");
        books.setBookCounts(1000);
        books.setDetail("值得一看");
        bookServiceImpl.addBook(books);
        System.out.println("  --}=========>"+books.getBookName());
    }
    @Test
    public void t3(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookService bookServiceImpl = context.getBean("bookServiceImpl", BookService.class);
        bookServiceImpl.delete(2);
        System.out.println("ok");
    }
    @Test
    public void t4(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookService bookServiceImpl = context.getBean("bookServiceImpl", BookService.class);
        Books books=new Books(1,"西游记",2,"世事无常");
        bookServiceImpl.updateBook(books);
    }
    @Test
    public void t5(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookService bookServiceImpl = context.getBean("bookServiceImpl", BookService.class);
        //传递的是int类型的数值
        Books books = bookServiceImpl.queryBookByID(3);
        System.out.println("--{==========>"+books.getDetail());
    }
    @Test
    public void t6(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookService bookServiceImpl = context.getBean("bookServiceImpl", BookService.class);
        //传递上两个参数
        PageBean<Books> pageBean = bookServiceImpl.queryBookByKeyword(99, 5, "", "");
        System.out.println(pageBean.toString());
    }
    @Test
    public void t7(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookService bookServiceImpl = context.getBean("bookServiceImpl", BookService.class);
        Books books = bookServiceImpl.queryBookByBookName("西游记");
        System.out.println(books);
    }
    @Test
    public void t8(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookService bookServiceImpl = context.getBean("bookServiceImpl", BookService.class);
        bookServiceImpl.queryBookByKeyword(1,5,"as","as");
    }
    @Test
    public void t9(){
       //路径
        String PATH="G:\\01_twenty_for\\src\\main\\java";
        //文件名
        String fileName=PATH+"easyExcel.xlsx";
        List<Books> list=new ArrayList<>();
        Books books=new Books(1,"西游记",2,"西天取经");
        list.add(books);
        EasyExcel.write(fileName, Books.class).sheet("模板").doWrite(list);
        System.out.println("ok");
    }
}